<template>
  <div>
    <div v-if="row.actions.length>2">
      <a @click="handleClickMore(row.actions[0].name, row)">{{ row.actions ? row.actions[0].label : '' }}</a>
      <Divider type="vertical" />
      <Dropdown @on-click="(name) => handleClickMore(name, row)"
                transfer>
        <a>更多
          <Icon type="ios-arrow-down" /></a>
        <DropdownMenu slot="list">
          <DropdownItem v-for="(item, i) in row.actions.slice(1)"
                        :key="i"
                        :name="item.name">{{ item.label }}</DropdownItem>
        </DropdownMenu>
      </Dropdown>
    </div>
    <div v-else>
      <a v-if="row.actions"
         @click="handleClickMore(row.actions[0].name, row)">{{ row.actions[0].label }}</a>
      <Divider v-if="row.actions && row.actions.length>1"
               type="vertical" />
      <a v-if="row.actions && row.actions.length>1"
         @click="handleClickMore(row.actions[1].name, row)">{{ row.actions[1].label }}</a>
    </div>
    <Modal v-model="auditModal"
           title="订单详情"
           footer-hide="true">
      <Form ref="formValidate"
            :model="formData"
            :label-width="100">
        <FormItem label="订单编号："
                  prop="orderNo">
          <span v-text="formData.orderNo"></span>
        </FormItem>
        <FormItem label="订单状态："
                  prop="state">
          <span v-text="formData.state"></span>
        </FormItem>
        <FormItem label="商品名称："
                  prop="goodsName">
          <span v-text="formData.goodsName"></span>
        </FormItem>
        <FormItem label="数量："
                  prop="num">
          <span v-text="formData.num"></span>
        </FormItem>
        <FormItem label="使用期限："
                  prop="term">
          <span v-text="formData.term"></span>
        </FormItem>
        <FormItem label="实付金额："
                  prop="money">
          <span v-text="formData.money"></span>元
        </FormItem>
        <FormItem label="商家名称："
                  prop="customer">
          <span v-text="formData.customer"></span>
        </FormItem>
        <FormItem label="商家账号："
                  prop="customer">
          <span v-text="formData.customer"></span>
        </FormItem>
        <FormItem label="下单时间："
                  prop="createOpeTime">
          <span v-text="formData.createOpeTime"></span>
        </FormItem>
      </Form>
    </Modal>
  </div>
</template>
<script>
    import { ApiRequest } from '@api/basePage';
    import dynamictableactions from '@/mixins/dynamictableactions'; // 混入通用代码
    export default {
        mixins: [
            dynamictableactions
        ],
        data () {
            return {
                auditModal: false,
                formData: {}
            }
        },
        methods: {
            //  操作更多选择
            handleClickMore (name, row) {
                let obj = {}; // 动作的对象信息
                row.actions.forEach(item => {
                    if (name === item.name) {
                        obj = item;
                        return false;
                    }
                })
                this.setTableRowData(row)
                if (obj.handleType === 'link') { // 操作类型为链接时，拼接参数跳转
                    let jumpPath = this.jumpPath + obj.name;
                    this.$router.push({ path: jumpPath, query: { 'uuid': row.uuid } })
                } else if (obj.handleType === 'confirm') { // 操作类型为confirm时 打开modal弹窗
                    if (name === 'View') {
                        this.getOrderDetail();
                    }
                } else if (obj.handleType === 'alert') {
                }
            },
            // 获取订单详情
            getOrderDetail () {
                let data = {
                    uuid: this.row.uuid
                }
                ApiRequest(this.requestApi.getThirdServicesOrderDetail.url, this.requestApi.getThirdServicesOrderDetail.type, data).then(res => {
                    this.formData = res.data;
                    this.auditModal = true;
                })
            }
        }
    }
</script>
